package org.hp.Servlet;

import com.alibaba.fastjson.JSON;
import org.hp.service.AService;
import org.hp.service.impl.AServiceImpl;
import org.hp.util.Layui;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.LayerUI;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@WebServlet("/LoginServlet")
public class LoginServlet extends javax.servlet.http.HttpServlet {
    AService as= new AServiceImpl();
    Layui layui=new Layui();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map  map = (Map) as.login("select * from user where uusername=? and upassword=?",request.getParameter("uusername"),request.getParameter("upassword"));
        if(map.size()>0){
           request.getSession().setAttribute("map",map);
           response.getWriter().write(JSON.toJSONString(layui.select(map)));
        }else{
            response.getWriter().write(JSON.toJSONString(layui.select(map)));
        }
    }
}
